from django.contrib.gis.db import models 
from django.contrib.auth.models import User

class Usuario(User):
    def __str__(self):
        return self.username
    
    class Admin:
        pass

# Create your models here.
class Recorrido(models.Model):
    linea = models.CharField(max_length=10)
    frecuencia = models.IntegerField()
    objects = models.GeoManager()
    
    def __unicode__(self):
        return self.linea

class Parada(models.Model):
  orden = models.IntegerField()
  objects = models.GeoManager()
  latitud = models.FloatField()
  longitud = models.FloatField()
  coordenadas = models.PointField(srid=4326)
  linea = models.ForeignKey(Recorrido)
  
  def _unicode_(self):
      return self.orden
      
  def ordenParada(self):
      return self.orden

  def latitudParada(self):
      return self.latitud
     
  def longitudParada(self):
      return self.longitud
    
class Unidad(models.Model):
  latitud = models.FloatField()
  longitud = models.FloatField()
  coordenadas = models.PointField(srid=4326)
  linea = models.ForeignKey(Recorrido)
  paradaasociada= models.ForeignKey(Parada)

  def _unicode_(self): 
     return model_id
        
class WorldBorders(models.Model):
    # Regular Django fields corresponding to the attributes in the
    # world borders shapefile.
    name = models.CharField(max_length=50)
    area = models.IntegerField()
    pop2005 = models.IntegerField('Population 2005')
    fips = models.CharField('FIPS Code', max_length=2)
    iso2 = models.CharField('2 Digit ISO', max_length=2)
    iso3 = models.CharField('3 Digit ISO', max_length=3)
    un = models.IntegerField('United Nations Code')
    region = models.IntegerField('Region Code')
    subregion = models.IntegerField('Sub-Region Code')
    lon = models.FloatField()
    lat = models.FloatField()

    # GeoDjango-specific: a geometry field (MultiPolygonField), and
    # overriding the default manager with a GeoManager instance.
    mpoly = models.MultiPolygonField()
    objects = models.GeoManager()

    # So the model is pluralized correctly in the admin.
    class Meta:
        verbose_name_plural = "World Borders"

    # Returns the string representation of the model.
    def __unicode__(self):
        return self.name
